package com.controller;

import java.text.ParseException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.bean.Complex;
import com.bean.Project;
import com.bean.Unit;
import com.service.ComplexService;
import com.service.ProjectService;
import com.service.UnitService;

@Controller
@RequestMapping("unit")
public class UnitAction {
	
	@Autowired
	private UnitService service;
	@Autowired
	private ProjectService pservice;
	
	
	
	//列表页面
	@RequestMapping("toList.do")
	public String toList(String name,String complexnumber,String uniteNumber,Model model){
		Map<String, Object> map = new HashMap<String,Object>();
		if(complexnumber != null && "".equals(complexnumber.trim())){
			complexnumber = null;
		}
		if(uniteNumber != null && "".equals(uniteNumber.trim())){
			uniteNumber = null;
		}
		if(name != null && "".equals(name.trim())){
			name = null;
		}
		map.put("complexnumber", complexnumber);
		map.put("uniteNumber", uniteNumber);
		map.put("name", name);
		List<Unit> list = service.select(map);
		model.addAttribute("list", list);
		return"unit/list";
	}
	
	
	//跳转添加页面
	@RequestMapping("toAdd.do")
	public String toAdd(Model model){
		Map<String, Object> map = new HashMap<String,Object>();
		List<Project> list = pservice.select(map);
		model.addAttribute("list", list);
		return "unit/add";
	}
	
	
	//添加
	@RequestMapping("add.do")
	public String add(Unit unit){
		service.insert(unit);
		return "redirect:toList.do";
	}
	
	
	//删除
	@RequestMapping("delete.do")
	public String delete(Integer id){
		service.deleteByPrimaryKey(id);
		return "redirect:toList.do";
	}
	
	
	
	//跳转修改
//	@RequestMapping("toUpdate.do")
//	public String toUpdate(Integer id,Model model){
//		Map<String, Object> map = new HashMap<String,Object>();
//		List<Project> list = pservice.select(map);
//		model.addAttribute("list", list);
//		Complex complex = service.selectByPrimaryKey(id);
//		model.addAttribute("complex", complex);
//		model.addAttribute("list", list);
//		return "complex/update";
//	}
	
	//修改
//	@RequestMapping("update.do")
//	public String update(Complex complex){
//		service.updateByPrimaryKeySelective(complex);
//		return "redirect:toList.do";
//	}

}
